COMP3141
Software System Design and Implementation (18s1)

Code Example (Week 3)

data Stack a
  = EmptyStack
  | MkStack a (Stack a)
  deriving (Show, Eq)

data Tree a
  = Leaf
  | Node a (Tree a) (Tree a)
  deriving (Show, Eq)  




depth :: Tree a -> Int
depth Leaf = 0
depth (Node _ t1 t2)
  = 1 + max (depth t1) (depth t2)

data RoseTree a 
  = RLeaf  
  | RNode a [RoseTree a]
  deriving (Show, Eq)

data Point = MkPoint Float Float deriving (Show, Eq)

data Shape 
  = Rect Point Float Float
  | Circ Point Float
  deriving (Show, Eq)

distPoint :: Point -> Point -> Float
distPoint (MkPoint x y)  _ 
  = error "nyi" 

name :: Shape -> String
name (Rect _ _ _) = "rectangle"
name (Circ _ _)   = "circle"

2018-06-14 Thu 18:28

Announcements RSS